-
Notifications
You must be signed in to change notification settings - Fork 550
string cast might throw exception #4555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.1.x
Are you sure you want to change the base?
Conversation
|
This pull request has been marked as ready for review. |
|
Does it also solve phpstan/phpstan#5952 ? |
| ]); | ||
| } | ||
|
|
||
| public function testBug13806(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this test (and/or its result) does not depend on php version
| $toStringMethod = $scope->getMethodReflection($exprType, '__toString'); | ||
| if ($toStringMethod !== null) { | ||
| if ($this->phpVersion->throwsOnStringCast()) { | ||
| if ($toStringMethod->getThrowType() !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, almost perfect 😊 But I think we're missing a few things:
- It should support
@throws voidas a means to mark "this does not throw exceptions". - It should respect
$this->implicitThrows. When throwType isnull, if this property is true, it means an implicit throw point should be added. If this property is false, it means that__toStringdoes not throw an exception.
There's already code in NodeScopeResolver handling these things - getMethodThrowPoint. Should be possible to reuse it.
closes phpstan/phpstan#13806